// Domien Nowicki & Raf Lempens
#include "QtSpinnerSprite.h"
#include <QPainter>
#include "QtBlendToEffect.h"
#include "QtSequentialAnimationEffect.h"
#include "QtScaleToEffect.h"
#include "QtRotateToEffect.h"


QtSpinnerSprite::QtSpinnerSprite(QtSprite *parent): QtPixmapSprite(parent), duration(500)
{
	SetDepth(1);

}

QtSpinnerSprite::~QtSpinnerSprite()
{
}

void QtSpinnerSprite::SetDirection(const Direction& newDirection)
{
	spinDirection = newDirection;
	if(spinDirection.IsEast() || spinDirection.IsWest())
	{
		SetResource("foreground", "spinner");
		AddResourceSpecification("foreground", newDirection.ToString());
	}
}




void QtSpinnerSprite::Rotate()
{
	if (spinDirection.IsWest())
	{		
		qreal newAngle = Angle() - 90;
		if (newAngle < 360)
			newAngle += 360;
		RotateLeftTo(newAngle, duration);

		Start();
	}
	else if (spinDirection.IsEast())
	{
		qreal newAngle = Angle() + 90;
		if (newAngle > 360)
			newAngle -= 360;
		RotateRightTo(newAngle, duration);

		Start();
	}
}







